package com.ck.demo.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class LangLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String lang = request.getParameter("lang");
        //获得本地化的默认值
        Locale locale = Locale.getDefault();
        if(!StringUtils.isEmpty(lang)){
            //ss： en_US  zh_CN 这个系统下两种情况，在通过_分割成数组
            String[] ss = lang.split("_");
            locale=new Locale(ss[0],ss[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
